package com.common.domain;



import com.common.convert.Convert;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

@XmlRootElement
public class Pagination<T> {

	/**
	 * 查询结果总条数
	 */
	private Long totalCount = 0L;

	/**
	 * 当前页码
	 */
	private Integer currentPage = 1;

	/**
	 * 查询结果总页数
	 */
	private Long pageNum = 0L;

	/**
	 * 每页显示的记录条数
	 */
	private Long pageSize = 15L;

	/**
	 * 每页的查询结果列表
	 */
	private List<T> pageList;

	public Pagination() {
	}

	public Pagination(List<T> pageList) {
		this.pageList = pageList;
	}

	public Pagination(List<T> pageList, Long totalCount, Integer currentPage, Long pageSize) {
		this.pageList = pageList;
		this.pageSize = pageSize;
		setTotalCount(totalCount);
		this.currentPage = currentPage;
	}

	public Pagination(List<T> pageList, Long totalCount, Integer currentPage, Integer pageSize) {
		this.pageList = pageList;
		this.pageSize = Convert.asLong(pageSize);
		setTotalCount(totalCount);
		this.currentPage = currentPage;
	}

	public Long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Long totalCount) {
		this.pageNum = (totalCount + this.pageSize - 1) / this.pageSize;
		this.totalCount = totalCount;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Long getPageNum() {
		return pageNum;
	}

	public Long getPageSize() {
		return pageSize;
	}

	public void setPageSize(Long pageSize) {
		this.pageSize = pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = Convert.asLong(pageSize);
	}

	public List<T> getPageList() {
		return pageList;
	}

	public void setPageList(List<T> pageList) {
		this.pageList = pageList;
	}
}
